package org.neuedu.chapter10_0705.demo01;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class MapDemo02 {
    public static void main(String[] args) {
        Map<String, Integer> map = new HashMap<>();
        map.put("java1", 201);
        map.put("java2", 202);
        map.put("java3", 203);
        map.put("java4", 204);
        map.put("java5", 205);
        map.put("java6", 206);
        map.put("java7", 207);

        // 1.Set keySet() : 返回key的Set集合
        Set<String> keys = map.keySet();
        System.out.println(keys);
        for (String key : keys) {
            System.out.print(key+"="+map.get(key)+" ");
        }
        System.out.println();

        // 2.迭代器遍历
        Iterator<String> iterator = keys.iterator();
        while (iterator.hasNext()) {
            String key = iterator.next();
            System.out.print(key+"="+map.get(key)+" ");
        }
        System.out.println();

        // 3.Entry遍历
        Set<Entry<String, Integer>> entrySet = map.entrySet();
        for (Entry<String, Integer> entry : entrySet) {
            System.out.print(entry.getKey()+"="+entry.getValue()+" ");
        }
    }
}
